﻿using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace K9Nano.AspNetCore.Extensions
{
    public static class ModelStateDictionaryExtensions
    {
        public static string GetErrors(this ModelStateDictionary modelState)
        {
            var sb = new StringBuilder();
            modelState.Values.Aggregate(sb, (seed, entry) =>
                entry.Errors.Aggregate(seed,
                    (seed2, error) => seed2.AppendLine(error.ErrorMessage + ";")));
            return sb.ToString();
        }
    }
}